import {getCategoryList} from '@/api/index'
import { topCaregory } from '@/utils/constants';
export default {
    namespaced: true,
    state: () => {
        return {
            cateList:topCaregory //默认值，如果请求不到数据的时候显示
        }
    },
    mutations: { //同步操作，修改
        setList(state,payload){
            state.cateList = payload;
        }
    },
    actions: { //异步，可以发送请求
        // 请求后台，加载菜单
        // eslint-disable-next-line no-unused-vars
        async getAllCategory({commit}){
            try {
                const res = await getCategoryList()
                // console.log(res)
                if(res.code === '200'){
                    commit('setList',res.data.cateList)
                }
            } catch (error) {
                console.log(error)
            }
        }
    },
    getters: {

    }
}